<!DOCTYPE html>
<html lang="zh" xmlns:th="https://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('编辑标签')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="tagAddForm" name="form-config-add">
        <div class="form-group">
            <input type="hidden" id="tagId" name="tagId" th:value="${tag.tagId}">
            <label class="col-sm-3 control-label">名称：</label>
            <div class="col-sm-8">
                <input id="tagTitle" name="tagTitle" class="form-control" type="text" th:value="${tag.tagTitle}">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "blog/tag";

    $("#tagAddForm").validate({
        rules: {
            tagTitle: {
                required: true,
                rangelength: [2, 10],
                remote: {
                    url: prefix + "/checkTagTitleUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        title: function () {
                            return $.common.trim($("#title").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "tagTitle": {
                required: "请输入标题",
                rangelength: "请输入长度为 {0} 至 {1} 之间的标题",
                remote: "标题已存在"
            },
        },
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = {
                "tagTitle": $("#tagTitle").val(),
                "tagId": $("#tagId").val()
            };
            $.operate.update(prefix + "/edit", data);
        }
    }
</script>
</body>
</html>
